#!/usr/bin/env groovy

def kubectl_auth = "c26898c2-92c3-4c19-8490-9cf8ff7918ef"

pipeline {
    agent {
        kubernetes {
            yaml '''
apiVersion: v1
kind: Pod
metadata:
  name: jenkins-slave
  namespace: jenkins-prod
spec:
  tolerations:
  - key: k8s-jenkins
    operator: Equal
    value: k8s-jenkins
    effect: NoSchedule
  containers:
  - name: kubectl
    #image: kostiscodefresh/kubectl-argo-rollouts:v1.6.0
    image: ccr.ccs.tencentyun.com/huanghuanhui/kubectl:v1.6.0
    imagePullPolicy: IfNotPresent
    command:
    - sleep
    args:
    - 99d
'''
        }
    }

environment {
AppName = "${AppName}"
}

    stages {
        stage('argo-rollouts + istio（金丝雀发布）（渐进式交付）') {
            steps {
              container('kubectl') {
              configFileProvider([configFile(fileId: "${kubectl_auth}", variable: 'kubeconfig')]) {
                sh """
                mkdir -p ~/.kube && cp ${kubeconfig} ~/.kube/config
                 /app/kubectl-argo-rollouts-linux-amd64 undo ${AppName} -n prod
                """
                   }
                }
            }
        }
    }
}